package org.fig.dependency.injection;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * @Description: 基于XML配置的 Constructor注入
 * @Author: Flynn Vanderboom
 * @Data: 2021/6/20 22:18
 */

public class XmlDependencyConstructorInjectionDemo {
    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

        String xmlResourcePath = "classpath:META-INF/dependency-injection-constructor.xml";

        //加载XML资源，解析并且生成BeanDefinition
        reader.loadBeanDefinitions(xmlResourcePath);
        //依赖查找并且创建Bean
        
        UserHolder userHolder = beanFactory.getBean(UserHolder.class);
        
        System.out.println(userHolder);
    }
}
